package laba3;

import interfaces.task3.StringDiv;
import interfaces.task3.StringUtils;

/**
 *
 * @author yakimovich
 */
public class StringDivImpl implements StringDiv {

    /**
     * divides numbers from the specified lines
     *
     * @return the result of division the specified numbers
     * @throws IllegalArgumentException when arguments do not contain numbers.
     */
    @Override
    public double div(String string, String string1) {
      StringUtils stringUtils = new StringUtilsImpl();
        double a;
        double b;
        
        try {
            a = stringUtils.parseDouble(string);
            b = stringUtils.parseDouble(string1);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("The specified strings "
                    + "can not parse.", e);
        }
        if (b == 0) {
            throw new ArithmeticException("Divisor can not be 0");
        }
        return a / b;
    }
}
